
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="attendance/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/commonly-used-show.css" />
    <script type="text/javascript" src="attendance/js/jquery.min.js"></script>
    <script type="text/javascript" src="attendance/js/bootstrap.js" ></script>

    <title>课程管理</title>

    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>

</head>

<body class="mybody">

 <jsp:include page="theTopMenuTeacher.jsp" />

 <div class="container">
    <h3 style="text-align: center">课程信息列表</h3>
    <table border="1" class="table table-bordered table-hover">
        <thead>
        <tr class="success">
            <th>序号</th>
            <th>课程编号</th>
            <th>课程名称</th>
            <th>任课老师</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody id="tbody-result">
        </tbody>

        <tr>
            <td colspan="6" align="center"><a class="btn btn-primary" href="${pageContext.request.contextPath}/addCourse">添加课程</a></td>
        </tr>

    </table>
</div>

<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    window.onload = function(){
        courseInfo();
    }

    function courseInfo(){
        var postUrl = "${pageContext.request.contextPath}/member/queryCourseInfo";

        var str = {
            "userId": userdt.result.id
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    alert(data.msg)
                }else {
                    var strtab = "";
                    //清空表格数据
                    $("#tbody-result").html("");


                    for (var i = 0; i < data.result.length; i++) {
                        strtab = "<tr>" + "<td>" + i + "</td>"
                            + "<td>" + data.result[i].id + "</td>"
                            + "<td>" + data.result[i].courseTitle + "</td>"
                            + "<td>" + data.result[i].instructor + "</td>"
                            + "<td>" + data.result[i].createTime + "</td>"
                            + "<td>" + "<a class=\"btn btn-default btn-sm\" href=${pageContext.request.contextPath}/leaveDetails1?id=" + data.result[i].id +  ">" + "修改" + "</a>" + "</tr>";
                        $("#tbody-result").append(strtab);//将数据追加进表格
                    }
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>